<template>
	<view>
		网络请求，以及数据缓存
		<button @click="getNet">发送GET请求</button>
		<button type="primary" @click="setStorage">存储</button>
		<button @click="getStorage">获取数据</button>
		<button @click="removeStorage">清除数据</button>
		<button @click="setStorageSync">同步存储数据</button>
		<button @click="getStorageSync">同步获取数据</button>
		<button @click="removeStorageSync">同步清除数据</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			getNet(){
				uni.request({
					method: 'GET',		//注意，这里在浏览器中存在跨域问题，而小程序中是不存在的
					url: 'http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince',
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: '请求成功...',
							duration:2000
						})
					}
				})
			},
			setStorage(){
				uni.setStorage({
					key: 'id',
					data: 80,
					success() {
						console.log("数据缓存成功...");
					}
				})
			},
			getStorage(){
				uni.getStorage({
					key:'id',
					success(res){
						console.log('获取成功',res,res.data)
					},
					fail() {
						console.log('数据不存在...');
					}
				})
			},
			removeStorage(){
				uni.removeStorage({
					key:'id',
					success() {
						console.log('数据清除成功...');
					}
				})
			},
			setStorageSync(){
				uni.setStorageSync('id',1000);
			},
			getStorageSync(){
				const res = uni.getStorageSync('id');
				console.log(res);
			},
			removeStorageSync(){
				uni.removeStorageSync('id');
			}
		}
	}
</script>

<style>

</style>
